/*=============================================================

PROGRAMMING TECHNIQUES FOR SUPERCOMPUTERS

Assignment Number 1

Task 0

Computation of Pi with Multiplication instead of Division

=============================================================*/

#include <stdio.h>
#include "timing.hh"
#include <iostream>


int main(int argc, char *argv[]) 
{
	double wcTimeStart,wcTimeEnd,cpuTimeStart,cpuTimeEnd,wcTime, cpTime;

	int slices = 100000000;
	double delta_x = 1.0/double(slices);
	double x = 0, sum = 0, Pi = 0;
	timing(wcTimeStart,cpuTimeStart);
	
	for (int i=0; i < slices; ++i) 
	{
		x = (i+0.5)*delta_x;
		sum += (4.0 * (1.0 + x * x));
	}
	Pi = sum * delta_x;

	timing(wcTimeEnd,cpuTimeEnd);
	
	wcTime=wcTimeEnd-wcTimeStart;
	long noFlops = slices*6;
	double mFlops = noFlops/wcTime/1000000;

	std::cout << "The Wall time is: " << wcTime << "sec"<<std::endl;		
	std::cout << "The Value of Pi computed is:(Not Accurate- But Printed to execute the Loop) " << Pi << std::endl;
	std::cout << "The MFLOP/sec is : " << mFlops <<std::endl;
	
	return 0;
}
